
package com.khadi.testcase.view.model;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

public class FieldTableModel extends AbstractTableModel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4681170316364881419L;

	private String[] columns;

	private List<HtmlFieldModel> data;

	public FieldTableModel(String[] columns) {
		this.columns = columns;
	}

	@Override
	public int getColumnCount() {
		return this.columns.length;
	}

	@Override
	public String getColumnName(int column) {
		return this.columns[column];
	}

	@Override
	public int getRowCount() {
		// TODO Auto-generated method stub
		return getData().size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {

		HtmlFieldModel guiModel = getValueAtRowIndex(rowIndex);
		if (guiModel != null) {
			switch (columnIndex) {
			case 0:
				return guiModel.getId();
			case 1:
				return guiModel.getName();
			case 2:
				return guiModel.getType();
			case 3:
				return guiModel.getValue();
			case 4:
				return guiModel.getClassName();
			default:
				break;
			}
		}
		return null;
	}

	public void setData(List<HtmlFieldModel> data) {
		this.data = data;
		fireTableDataChanged();
	}

	public List<HtmlFieldModel> getData() {
		if (this.data == null) {
			data = new ArrayList<HtmlFieldModel>();
		}
		return data;
	}

	private HtmlFieldModel getValueAtRowIndex(int rowIndex) {
		return getData().get(rowIndex);
	}

}
